﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cinchoo.Core;

namespace ChoWorkflowServer.Model
{
    public static class ChoJobNameHelper
    {
        public static string ToJobName(string taskName, string scheduleName)
        {
            ChoGuard.ArgumentNotNullOrEmpty(taskName, "TaskName");
            ChoGuard.ArgumentNotNullOrEmpty(scheduleName, "ScheduleName");

            return "{0}/{1}".FormatString(taskName, scheduleName);
        }

        public static string ToJobName(string taskName, string scheduleName, int batchId)
        {
            ChoGuard.ArgumentNotNullOrEmpty(taskName, "TaskName");
            ChoGuard.ArgumentNotNullOrEmpty(scheduleName, "ScheduleName");

            return "{0}/{1}/{2}".FormatString(taskName, scheduleName, batchId.ToString());
        }

        public static Tuple<string, string> FromJobName(this string jobName)
        {
            ChoGuard.ArgumentNotNullOrEmpty(jobName, "JobName");

            string[] tokens = jobName.SplitNTrim("/");
            if (tokens == null || tokens.Length != 2)
                throw new ArgumentException("Invalid jobname passed.");

            return new Tuple<string, string>(tokens[0], tokens[1]);
        }
    }
}
